﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Hfabase.DataBase
{
    /// <summary>
    /// 数据库连接管理程序
    /// </summary>
    public class ConnectionManager : Collections.Singleton<ConnectionManager>
    {
        public ConnectionManager()
        {
        }

        /// <summary>
        /// 获取一个连接
        /// </summary>
        /// <returns></returns>
        public IDbConnection GetConnection()
        {
            string strType = Configs.ConfigManager.Instance.GetNodeAttrValue("/Appconfig/Database/type", "value");
            string strconnstr = Configs.ConfigManager.Instance.GetNodeAttrValue("/Appconfig/Database/connstr", "value");

            try
            {
                ConnectionType type = (ConnectionType)(Enum.Parse(typeof(ConnectionType), strType));
                return ConnectionFactory.CreatConnection(type, strconnstr);
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
